package com.hc.wego.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hc.wego.bean.PageBean;
import com.hc.wego.domain.entity.Advertise;
import com.hc.wego.domain.query.AdvertiseQuery;
import com.hc.wego.mapper.AdvertiseMapper;
import com.hc.wego.service.AdvertiseService;
import org.springframework.stereotype.Service;

@Service
public class AdvertiseServiceImpl extends ServiceImpl<AdvertiseMapper, Advertise> implements AdvertiseService {

    @Override
    public PageBean<Advertise> getPage(AdvertiseQuery query) {
        final Long pageNum = query.getPageNum();
        final Long pageSize = query.getPageSize();

        QueryWrapper<Advertise> queryWrapper = new QueryWrapper<>();

        final String name = query.getName();
        if (name != null) {
            queryWrapper.like("name", name);
        }

        IPage<Advertise> page = new Page<>(pageNum, pageSize);
        this.page(page, queryWrapper);

        return PageBean.page2pageBean(page);
    }
}
